<?php

namespace Common\Taglib;

use Common\Lib\Relation;

class bbschat
{
    public function run($opt)
    {
        $rid = intval($opt['rid']);
        $page = intval($opt['page']);
        $sort = trim($opt['sort']) ?: 'id';
        $num = empty($opt['num']) ? 15 : intval($opt['num']);

        if ($rid) {
            $map['rid'] = $rid;
        }

        $result = D('BbsReplyChat')->get_list($map, $page, $sort, $num);

        $list = $result['list'];
        $list = Relation::belongsTo($list, 'User', 'send_uid', 'uid', 'senduser', array(D('User'), 'auto_user_fill'));
        $list = Relation::belongsTo($list, 'User', 'to_uid', 'uid', 'touser', array(D('User'), 'auto_user_fill'));

        $result['list'] = $list;

        return $result;
    }
}